<template>
	<view class="refund">
		<view class="wrapper">
			<view class="top d-flex">
				<u-image :src="data.image" width="190rpx" height="190rpx" radius="12rpx"></u-image>
				<view style="margin-left: 30rpx;">
					<view class="name">{{ data.name }}</view>
					<!-- <view class="date">{{ data.date }}</view> -->
					<!-- <view class="count">×{{ data.order_money }}</view> -->
				</view>
				<!-- <view class="menu" @click="backUp">
					<text>退款</text>
				</view> -->
			</view>

			<u-line margin="30rpx 0" color="#E5E5E5"></u-line>

			<view class="flex-between">
				<view>
					退款总金额
					<!-- <text style="color: #BEBEBE;">(实付金额)</text> -->
				</view>
				<price :value="data.order_money" color="#FF4105"></price>
			</view>

			<u-line margin="30rpx 0" color="#E5E5E5"></u-line>

			<view>
				<view class="flex-between">
					<view class="">退回账户</view>
					<view class="flex-align">
						<!-- <u-icon name="weixin-fill" color="#00c800" size="58rpx"></u-icon> -->
						<view>原账户</view>
					</view>
				</view>

				<view style="color: #888888; margin-top: 14rpx; font-size: 24rpx;">
					<!-- (<text style="color: #FF8F05;">1-3个工作日内</text>到账，若原路退回失败，款项会尝试退还至您美团 钱包的余额) -->
					(预计<text style="color: #4BA677;">1-3个工作日内</text>到账)
				</view>
			</view>

			<u-line margin="30rpx 0" color="#E5E5E5"></u-line>

			<view slot="title" class="u-cell__title required">退款原因</view>
			<u-textarea v-model="data.content" placeholder="填写原因" border="none" height="180"></u-textarea>
		</view>


		<view class="bottom-add-btn">
			<u-button text="提交" shape="circle" @click="refund"
				color="linear-gradient(0deg, rgb(47, 117, 250) 0%, rgb(82, 142, 255) 100%)"></u-button>
		</view>
	</view>
</template>

<script>
	const person = require("@/api/personal/index.js");
	export default {
		data() {
			return {
				data: {
					name: '',
					date: '',
					price: '',
					count: '',
					image: '',
					id: '',
					content: '',
					order_money: '',
					pay_method: ''
				},
			}
		},
		onLoad(options) {
			console.log(options, '999')
			this.data.name = options.goods_name
			this.data.date = options.consumption_type
			this.data.price = options.amount_payable
			this.data.count = options.orderlength
			this.data.image = options.goods_image
			this.data.order_money = options.order_money
			this.id = options.id
			this.pay_method = options.pay_method

		},
		methods: {
			backUp() {
				console.log(2233)
				var that = this
				uni.requestSubscribeMessage({
					tmplIds: ['R3prlifwIbScJTer8rlTpDaJE0tTRJ567oMtSsGmhek'],
					success(res) {
						console.log(res, '132132')
						if (res.R3prlifwIbScJTer8rlTpDaJE0tTRJ567oMtSsGmhek == "accept") {
							// that.refundNotice()
							uni.openSetting({
								withSubscriptions: 'true',
								success(res) {
									console.log(res.authSetting, 'ooooo')
								}
							});
						}
					}
				})
			},
			// async refundNotice(){
			//   let postParam = {
			//     touser: uni.getStorageSync('openid'),
			//     template_id: 'R3prlifwIbScJTer8rlTpDaJE0tTRJ567oMtSsGmhek',
			//     page: '/pages/index/index',
			// 	applet_id: this.$https.applet_id,

			//     date9: '2022-12-01 01:01:01',
			//     amount3: '33.00',
			//     character_string1: '212312113123123',
			//     thing2: '22.00',
			//     thing8: '王总一路长虹阿',
			//   }
			//   let result = await person.refundNotice(postParam)
			// },
			// 获取我的退款订单    支付方式 1微信 2支付宝 3现金 4扫呗 5、会员卡
			async refund() {
				if (this.data.content == '') {
					/* uni.showToast({
						title: '请输入退款原因',
						icon: 'exception',
						duration: 850
					}); */
					uni.showModal({
						content: '请输入退款原因',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				} else {
					let that = this;

					uni.showModal({
						title: '提示',
						// 提示文字
						content: '是否退款？',
						// 取消按钮的文字自定义
						cancelText: "取消",
						// 确认按钮的文字自定义
						confirmText: "确认",
						//删除字体的颜色
						confirmColor: '#000000',
						//取消字体的颜色
						cancelColor: '#999',
						success: function(res) {
							if (res.confirm) {
								let postData = {
									app_id: that.$https.weixinAppId,
									project_id: getApp().globalData.projectId,
									open_id: uni.getStorageSync("openid"),
									order_item_id: that.id,
									refund_reason: that.data.content,

								};
								if (that.pay_method == 1) {
									person.refund(postData).then(result => {
										console.log(result, '1111')
										if (result.code == 1) {
											uni.showToast({
												title: result.info,
												icon: 'exception',
												duration: 500
											});
											uni.navigateTo({
												url: '/pages/personal/orders/orders?tab=2'
											})
										} else {
											uni.showModal({
												title: result.data.msg,
												showCancel: false,
												success: function(res) {
													if (res.confirm) {
														uni.navigateTo({
															url: '/pages/personal/orders/orders?tab=2'
														})
													} else if (res.cancel) {
														console.log('用户点击取消');
													}
												}
											});
										}
									})
								} else if (that.pay_method == 4) {
									person.sbpayrefund(postData).then(result => {
										if (result.code == 1) {
											uni.showToast({
												title: result.info,
												icon: 'exception',
												duration: 500
											});
											uni.navigateTo({
												url: '/pages/personal/orders/orders?tab=2'
											})

										} else {
											uni.showModal({
												title: result.data.msg,
												// content: data[0],
												showCancel: false,
												success: function(res) {
													if (res.confirm) {
														uni.navigateTo({
															url: '/pages/personal/orders/orders?tab=2'
														})
													} else if (res.cancel) {
														console.log('用户点击取消');
													}
												}
											});
										}
									})

								} else if (that.pay_method == 5 || that.pay_method == 6 || that.pay_method == 19) {
									person.moniRefund(postData).then(result => {
										if (result.code == 1) {
											uni.showToast({
												title: result.info,
												icon: 'exception',
												duration: 500
											});
											uni.navigateTo({
												url: '/pages/personal/orders/orders?tab=2'
											})

										} else {
											uni.showModal({
												title: result.info,
												showCancel: false,
												success: function(res) {
													if (res.confirm) {
														uni.navigateTo({
															url: '/pages/personal/orders/orders?tab=2'
														})
													} else if (res.cancel) {
														console.log('用户点击取消');
													}
												}
											});
										}
									})
								}
							}
						}
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.refund {
		min-height: 100vh;
		background-color: #f7f7f7;
		padding-bottom: calc(150rpx + env(safe-area-inset-bottom));

		.wrapper {
			background-color: #fff;
			padding: 30rpx;

			.u-cell__title {
				color: #333;
				font-size: 32rpx !important;
				font-weight: 500;

				&.required {
					&::before {
						content: '*';
						color: #fb2222;
					}
				}
			}
		}

		.top {
			.name {
				color: #333;
				margin-bottom: 20rpx;
			}

			.date {
				margin-bottom: 30rpx;
				background-color: #f3f3f3;
				color: rgb(136, 136, 136);
				font-size: 24rpx;
				border-radius: 100px;
				padding: 4rpx 20rpx;
			}
		}

		/deep/.u-textarea {
			background-color: #f3f3f3;
			margin-top: 30rpx;
		}
	}
</style>